package com.example.topicfromjinzhuan2024national

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.core.view.GravityCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentPagerAdapter
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.topicfromjinzhuan2024national.databinding.ActivityBreakRulesBinding

class BreakRules : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        var binding=ActivityBreakRulesBinding.inflate(layoutInflater)
        setContentView(binding.root)

        var homeRecyList = ArrayList<HomeRecyListObject>()
        homeRecyList.add(HomeRecyListObject(R.drawable.start,"红绿灯管理"))
        homeRecyList.add(HomeRecyListObject(R.drawable.book,"车辆违章"))
        homeRecyList.add(HomeRecyListObject(R.drawable.look,"ETC账户"))
        homeRecyList.add(HomeRecyListObject(R.drawable.look,"用户中心"))
        homeRecyList.add(HomeRecyListObject(R.drawable.look,"数据分析"))
        homeRecyList.add(HomeRecyListObject(R.drawable.look,"公交查询"))
        homeRecyList.add(HomeRecyListObject(R.drawable.look,"天气预报"))
        homeRecyList.add(HomeRecyListObject(R.drawable.download,"用户退出"))
        var layout= LinearLayoutManager(this)
        /*layout.orientation=LinearLayoutManager.VERTICAL*/
        binding.homeRecy.layoutManager=layout
        binding.homeRecy.adapter=HomeRecyAdapter(homeRecyList)

        binding.breakRulesImgMenu.setOnClickListener {
            binding.drawLayout.openDrawer(GravityCompat.START)
        }

        var titles= arrayOf("违章视频","违章图片")
        var fragments=ArrayList<Fragment>()
        fragments.add(Fragment1())
        fragments.add(Fragment2())
        //supportFragmentManager 是 FragmentManager 的一个实例，用于管理活动中的Fragment。
        //这是一个标志，用于指定ViewPager中Fragment的行为。BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT 表示只有当前显示的Fragment会处于活动状态（即调用其onResume()方法），而其他Fragment则处于暂停状态（onPause()）。
        binding.breakRulesViewPager.adapter=object:FragmentPagerAdapter(supportFragmentManager,
            BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT){
            override fun getCount(): Int=titles.size

            override fun getItem(position: Int): Fragment =fragments.get(position)

            override fun getPageTitle(position: Int): CharSequence? =titles[position]
        }
        binding.tab.setupWithViewPager(binding.breakRulesViewPager)
    }
}